﻿using System.Collections;
using UnityEngine;


public class MonsterStatePatrol : FSMState
{
    private MonsterController monster => fsm.role as MonsterController;
    private int v;
    public override void Enter()
    {
        v = 0;
        monster.agent.SetDestination(monster.patrolPoint[v]);
    }

    public override void Exit()
    {
        monster.home = monster.transform.position;
    }

    public override void Update()
    {
        monster.FindTarget();

        if ((monster.transform.position - monster.agent.nextPosition).sqrMagnitude < 1)
        {
            v++;
            if(v > monster.patrolPoint.Count)
                v = 0;  
            monster.agent.SetDestination(monster.patrolPoint[v]);
        }

        if (monster.target != null)
        {
            fsm.SetState("Pursuit");
        }
    }
}